angular.module('mamApp').controller('noticeMessageController', ['$scope', '$state','messageManager', 'noticeManager','$sce','ImsDialog',
    function ($scope, $state,messageManager,noticeManager,$sce,ImsDialog) {
    $scope.$sce=$sce;

    $scope.search = {
        status:$state.params.status,
        pageNo:$state.params.pageNo || 1,
        pageSize:$state.params.pageSize||10
    };

    $scope.paginationConf = {
        currentPage: $state.params.pageNo || 1,
        itemsPerPage: $state.params.pageSize || 10,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, $scope.search)
        }
    };

    $scope.tabClick=function (index) {
        $scope.search.pageNo=1;
        $scope.search.status = index;
        $state.go($state.current.name, $scope.search);
    };

    if ($scope.search.status == 'notice'||!$scope.search.status){
        noticeManager.noticeList($scope.search.pageNo, $scope.search.pageSize).then(function (result) {
            $scope.noticeList = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;
        });

    } else {
        messageManager.messageList($scope.search.pageNo, $scope.search.pageSize).then(function (result) {
            $scope.messageList = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;
        });
    }

    $scope.messageDelete = function(item){
        ImsDialog.open({title:"删除消息",message:'是否删除该条消息？'}).then(function (a) {
            if(a=="ok"){
                messageManager.messageDelete(item.id).then(function (result) {
                    if (result.data.c == 's'){
                        $state.reload();
                    }
                })
            }
        })
    };

    $scope.readMessage = function(item){
        messageManager.messageStatus(item.id).then(function (result) {
            if (result.data.c == 's'){
            }
        })
    };



}]);

